package com.libbase

import kotlin.properties.ObservableProperty
import kotlin.reflect.KProperty

class Observing<T : Any>(
    initialValue: T,
    private val willSet: (newValue: T) -> Unit = { },
    private val didSet: (oldValue: T) -> Unit = { }
) : ObservableProperty<T>(initialValue) {
    override fun beforeChange(property: KProperty<*>, oldValue: T, newValue: T): Boolean =
        true.apply { willSet(newValue) }

    override fun afterChange(property: KProperty<*>, oldValue: T, newValue: T) = didSet(oldValue)
}